package com.hifar.test.oaApi.common;

import java.io.ByteArrayOutputStream;

public class MarshallerUtil {

	// 公共参数：格式
	public static final String ARG_FORMAT = "format";
	public static final String JSON = "json";
	public static final String XML = "xml";

	public static ApiMarshaller getMarshaller(String f) {
		if (XML.equals(f)) {
			return new JaxbXmlMarshaller();
		}

		return new JsonMarshaller();
	}

	public static String wrapReturn(Object r, String f) {
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ApiMarshaller marshaller = getMarshaller(f);
		marshaller.marshaller(r, bos);
		try {
			return bos.toString("utf-8");
		} catch (Exception e) {
		}
		return bos.toString();
	}

}
